/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.example.business;

import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

import org.merak.core.web.HttpRequest;
import org.merak.core.web.HttpResponse;
import org.merak.core.web.mvc.PublicBusinessLogic;

public class SendFile extends PublicBusinessLogic {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private final static String view = null;

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	@Override
	public String execute(HttpRequest request, HttpResponse response)
		throws Exception
	{

		// Open a connection to remote resource
		URL           addr = new URL("http://localhost:8080/MerakCore/Main?b=RequestFile");
		URLConnection conn = addr.openConnection();

		/* Configure this connection as a form. It will do a post to the
		 * remote server requesting the data */
		conn.setRequestProperty("Content-Type", "application/octet-stream");
		conn.setRequestProperty("content-disposition", "attachment; filename=hello.txt");
		conn.setRequestProperty("b", "SendFile");
		conn.setDoOutput(true);
		PrintWriter pw = new PrintWriter(conn.getOutputStream());
		pw.println("Olllá Enfermeira!!");
		pw.close();
		conn.getInputStream();

		// Read the remote server's response
		return view;

	}
	//****************************************************************************

}
